package slap.mvc.scope;

import java.util.HashMap;
import java.util.Map;

import jodd.util.StringUtil;

import slap.http.Cookie;
import slap.http.Request;
import slap.paradigm.ModelsContext;

public class Session extends ModelsContext {

	public static final String COOKIE_SESSION_ID = "SLAP_SESSION_ID";

	private static Map<String, Session> SESSION_MAP = new HashMap<String, Session>();

	private static ThreadLocal<String> currentId = new ThreadLocal<String>();

	private String id;

	public Session(String id) {
		this.id = id;
	}

	public static void setCurrent(String id) {
		currentId.set(id);
	}

	public static Session current() {
		String id = currentId.get();
		Session cs = SESSION_MAP.get(id);
		if (cs == null) {
			cs = new Session(id);
			SESSION_MAP.put(id, cs);
		}
		return cs;
	}

	public String getId() {
		return id;
	}

	@Override
	public String toString() {
		return data.toString();
	}
}